/*****************************************************************
 *@Copyright all rights reserved ? 2014 Yuga
 *@author Oplink OMS
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.sys.entity;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.oplink.webbase.common.persistence.DataEntity;
import com.oplink.webbase.modules.sys.dto.ITreeDTO;

/**
 * 系统菜单Entity
 * 
 * @author Oplink OMS
 * @version 2014-09-02
 */
@Entity
@Table(name = "sys_menu")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Menu extends DataEntity implements ITreeDTO {

	private static final long serialVersionUID = 1L;
	private User user;
	private int sort; // ����
	private String parentId; // 父级节点
	private String parentName; // 父级节点
	private String parentIds; // 父级节点路径
	private String fieldType;//
	private String icon; // 图标字符
	private String url; // 路径
	private String label; // 显示菜单名称
	private String permission; // 登录名
	private String isEnable; // 是否禁用菜单

	public Map<String, Menu> children = new TreeMap<String, Menu>(new Comparator<String>() {

		@Override
		public int compare(String o1, String o2) {
			return o1.compareTo(o2);
		}
	});

	@Override
	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	@Override
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Override
	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Override
	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	// JPA ����USER_ID�еĶ��һ��ϵ����
	@ManyToOne
	@JoinColumn(name = "user_id")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@NotNull
	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}
}
